<template>
  <div class="app-container">
    <div class="customContainer">
      <div class="detail_title">
        <div>
          <span style="margin-right:10px" v-show="showType>1">退货单号：{{order_no}}</span>
          <el-select @change="storeChange" v-show="showType<3" :disabled="showType==2" size="small" filterable placeholder="请选择退货方" v-model="saveForm.store_id"
            style="width:300px;">
            <el-option v-for="item in store_list" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
        <el-button v-show="showType<3" type="primary" size="small" @click="addClick()">添加退货礼品</el-button>
      </div>
      <div v-show="showType==2" style="margin-bottom:10px">说明：{{time}} 由 {{nick}} 打回 意见是：{{remark}}</div>
      <!-- 列表 -->
      <el-table highlight-current-row :data="list" v-loading.body="listLoading" border size="small">
        <el-table-column align="center" label='序号' width="50">
          <template slot-scope="scope">
            <span class="indexColor">{{scope.$index+1}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="图片" prop="creat_time" width="80">
          <template slot-scope="scope">
            <div v-viewer="options" class="images fit">
              <img :src="scope.row.thumb" :data-source="scope.row.img" class="image" :key="scope.row.thumb" :alt="scope.row.img.split('?image=').pop()">
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="名称">
          <template slot-scope="scope">
            <el-button type="text" @click="showInfo(scope.row.gift_id)">{{scope.row.gift_name}}</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" label="礼品编号" prop="gift_id"></el-table-column>
        <el-table-column align="center" label="成本价(元)" prop="money_cost"></el-table-column>
        <el-table-column v-if="showType<3" align="center" label="可退数量" key="remain_num" prop="remain_num">

        </el-table-column>
        <el-table-column align="center" label="退货数量(个)">
          <template slot-scope="scope">
            <el-input v-if="scope.row.isSave" :maxlength="6" v-model="scope.row.order_num" @blur="inputBurl(scope.row)" placeholder="请输入数量"></el-input>
            <span v-else>{{scope.row.order_num}}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="showType==3" align="center" label="实收数量(个)" prop="arrive_num" key="arrive_num"></el-table-column>
        <el-table-column align="center" label="退货金额(元)">
          <template slot-scope="scope">
            <span>
              {{scope.row.order_num*scope.row.money_cost|keepTwoNum}}
            </span>
          </template>
        </el-table-column>
        <el-table-column v-if="showType==3" align="center" label="实收金额(个)" prop="arrive_money" key="arrive_money"></el-table-column>
        <el-table-column v-if="showType<3" align="center" label="操作" width="100" key="set">
          <template slot-scope="scope">
            <el-button type="danger" size="mini" @click="delClick(scope.$index)">移除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 弹框 -->
    <el-dialog width="400px" title="礼品其他信息" :visible.sync="infoDialog">
      <div class="info_dialog">
        <div>名称：{{gift_info.gift_name}}</div>
        <div>礼品编号：{{gift_info.id}}</div>
        <div>神采编号：{{gift_info.no_obsolete}}</div>
        <div>国标码：{{gift_info.gb_code}}</div>
        <div>一级类别：{{gift_info.one_type}}</div>
        <div>二级类别：{{gift_info.tow_type}}</div>
        <div>三级类别：{{gift_info.three_type}}</div>
        <div>材质：{{gift_info.texture}}</div>
        <div>产品尺寸：{{gift_info.product_size}}</div>
        <div>包装尺寸：{{gift_info.packing_size}}</div>
      </div>
    </el-dialog>
    <!-- 新增弹框 -->
    <el-dialog width="400px" title="添加礼品" :visible.sync="addDialog" @close="addCallOf">
      <div>
        <el-input style="width:290px;margin-right:10px" size="small" v-model="addData.id" placeholder="请输入完整的礼品编号"></el-input>
          <dj-button size="small" @search="searchClick">
            <template #default>搜索</template>
          </dj-button>
      </div>
      <div class="gift_info">
        <div class="gift_img">
          <img height="70px" :src="add_gift_info.thumb">
        </div>
        <div class="info_dialog add">
          <div>名称：{{add_gift_info.gift_name}}</div>
          <div>成本价：{{add_gift_info.money_cost}}</div>
          <div>礼品编号：{{add_gift_info.id}}</div>
          <div>神采编号：{{add_gift_info.no_obsolete}}</div>
          <div>国标码：{{add_gift_info.gb_code}}</div>
          <div>一级类别：{{add_gift_info.one_type}}</div>
          <div>二级类别：{{add_gift_info.tow_type}}</div>
          <div>三级类别：{{add_gift_info.three_type}}</div>
          <div>材质：{{add_gift_info.texture}}</div>
          <div>产品尺寸：{{add_gift_info.product_size}}</div>
          <div>包装尺寸：{{add_gift_info.packing_size}}</div>
          <div>箱规：{{add_gift_info.box_num}}</div>
          <div>可退库存：{{add_gift_info.remain_num}}</div>
        </div>
        <div class="gift_num">
          <div class="num_tag">数量</div>
          <el-input-number size="small" v-model="gift_num" :min="1" :max="add_gift_info.remain_num*1>999999?999999:add_gift_info.remain_num*1"
            :step="add_gift_info.box_num*1>0?add_gift_info.box_num*1:1"></el-input-number>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button :disabled="!add_gift_info.id" type="primary" size="mini" @click="addClick(1)">添加</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 提交订单弹出窗口 -->
    <el-dialog :visible.sync="showConDig" width="1000px" title="收货信息" class="myorderDialog" @close="confirmCallOf">
      <el-row>
        <el-col :span=7>
          <div class="row-block">
            <span style="width:30%;text-align:right;font-size:14px">退货渠道：</span>
            <el-select :disabled="showType==2" size="small" @change="typeChange" placeholder="请选择退货渠道" v-model="saveForm.type" filterable style="width:70%px">
              <el-option v-for="item in type_list" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </div>
        </el-col>
        <el-col :span=7>
          <div class="row-block">
            <span style="text-align:right;font-size:14px;margin-left:28px">收货方：</span>
            <el-select :disabled="showType==2" @change="receChange" size="small" placeholder="请选择收货方" v-model="saveForm.receice_id" filterable
              style="width:196px">
              <el-option v-for="item in rece_list" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </div>
        </el-col>
        <el-col v-show="saveForm.type==1" :span=10>
          <div class="row-block" style="margin-left:35px">
            <span style="text-align:right;font-size:14px;">约定退款金额：</span>
            <el-input size="small" :maxlength="9" placeholder="请输入约定退款金额" v-model="saveForm.appoint_money" style="width:150px"></el-input>
          </div>
        </el-col>
      </el-row>
      <el-row v-show="saveForm.type==2">
        <el-col :span=7>
          <div class="row-block">
            <span style="width:30%;text-align:right;font-size:14px">联系人：</span>
            <el-input disabled size="small" style="width:70%;font-size:14px" placeholder="请输入姓名" v-model="saveForm.man_name"></el-input>
          </div>
        </el-col>
        <el-col :span=7>
          <div class="row-block">
            <span style="width:30%;text-align:right;font-size:14px">电话：</span>
            <el-input disabled size="small" style="width:70%;" placeholder="请输入手机号码" v-model="saveForm.phone"></el-input>
          </div>
        </el-col>
        <el-col :span=10>
          <div class="row-block">
            <div style="width:30%;height:50%;">
              <div style="width:388px;height:50%;display:flex;margin-left:22px;">
                <!-- 地区 -->
                <span style="font-size:14px;text-align:right;display:inline-block;width:75px;line-height:29px;padding-right:2px">地区：</span>
                <el-form :inline="true" class="demo-form-inline" size="small">
                  <el-form-item>
                    <keep-alive>
                      <dj-region v-if="showConDig" :updateData="reg" :getName="true" :disabled="true" :isClear="clearRegion" @provVal="provVal(arguments)"
                        @cityVal="cityVal(arguments)" @areaVal="areaVal(arguments)" ref="region"></dj-region>
                    </keep-alive>
                  </el-form-item>
                </el-form>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <div v-show="saveForm.type==2" class="row-block-full">
        <span style="width:8.75%;text-align:right;font-size:14px">详细地址：</span>
        <el-input disabled style="width:91.25%;font-size:14px" type="textarea" :rows="2" :maxlength="160" placeholder="请输入详细地址" resize="none"
          v-model="saveForm.address"></el-input>
      </div>
      <div class="row-block-full">
        <div style="width:8.75%;text-align:right;font-size:14px">订单信息：</div>
        <p style="width:91.25%;text-align:center;font-size:16px">
          退货种类：{{list.length}}种 退货数量：{{allNum}}个 退货金额(不含运费)：{{allTotal|keepTwoNum}}元
        </p>
      </div>
      <div class="row-block-full">
        <span style="width:8.75%;text-align:right;font-size:14px">订单备注：</span>
        <div style="width:91.25%;font-size:14px">
          <el-input style="display:inline-block;width:100%;" type="textarea" :rows="4" placeholder="备注" v-model="saveForm.remark" resize="none"
            :maxlength="160"></el-input>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showConDig=false">返回修改</el-button>
        <el-button type="primary" @click="saveClick()">确认提交</el-button>
      </div>
    </el-dialog>
    <!-- 自定义底部 -->
    <div class="bottom_box">
  
      <div v-show="showType<3" class="pull-right">
        <el-button v-show="showType==2" @click="closeOrder" type="primary" size="small">关闭</el-button>
        <el-button v-show="showType<3" @click="save()" :disabled="list.length==0" type="primary" size="small">提交</el-button>
      </div>
      <div class="pull-right total">
        <span>退货种类：{{list.length}} 种</span>
        <span>退货数量：{{allNum}} 个</span>
        <span>退货金额 (不包含运费)：{{allTotal|keepTwoNum}} 元</span>
      </div>
   
    </div>
  </div>
</template>
<script>
import { getStore, getGift, supplier, supplierInfo, house, houseInfo, setOrder, getList, getPage, getInfo, close } from '@/api/warehouse/rtODetail';
import { positiveInt, mobile, greater0to999999dot } from '@/utils/validate';
export default {
  data() {
    return {
      showType: 1, //1 新建  2 修改  3 查看
      title: '新建退货单',
      listLoading: false,
      infoDialog: false,
      addDialog: false,
      showConDig: false, //收货信息弹窗
      isSave: false,
      isACheck: false,
      isFirst: false, //修改时第一次打开弹窗
      store_list: [], //退货方
      rece_list: [], //收货方
      sup_list: [], //供应商名称
      house_list: [], //中央仓名称
      rece_info: {}, //收货方信息
      clearRegion: false, // 清空子组件region中的值
      type_list: [
        { id: '1', name: '退供应商' },
        { id: '2', name: '退中央仓' }
      ],
      saveForm: {
        store_id: '',
        house_id: '',
        receice_id: '',
        man_name: '',
        phone: '',
        address: '',
        remark: '',
        appoint_money: ''
      },
      isShowAddGift: false,
      reg: {},
      list: [],
      // allList:[],
      oldData: [],
      gift_num: 1,
      id: '',
      receice_id: '',
      order_no: '',
      time: '',
      nick: '',
      remark: '',
      status: '0',
      type: '',
   
      addData: {
        id: ''
      },
      delData: [],
      route: { name: 'warehouse/rtODetail' },
      options: {
        //预览图配置
        toolbar: true,
        url: 'data-source'
      },
      gift_info: {},
      add_gift_info: {}
      // rules:{
      //     order_num: [
      //         { required: true, validator: vNum , trigger: 'blur'}
      //     ],
      // }
    };
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      //当进入组件之前，执行 beforRouteEnter 路由钩子函数 ,//参数vm就是当前组件的实例。
      if (vm.$route.params.routerflag) {
        vm.pageCallOf();
        vm.showType = vm.$route.params.routerflag;
        vm.title = vm.showType == 1 ? '新建退货单' : '修改退货单';
        vm.saveForm.store_id = vm.$route.params.store_id ? vm.$route.params.store_id : '';
        if (vm.showType < 3) {
          vm.getStoreList();
          vm.getSupplier();
          vm.getHouse();
        }
        if (vm.showType > 1) {
          vm.order_no = vm.$route.params.order_no;
          vm.id = vm.$route.params.id;
          vm.fatchData();
          if (vm.showType == 2) {
            vm.getOrderInfo();
            vm.isFirst = true;
          }
        }
        if (vm.showType == 3) {
          vm.status = vm.$route.params.status;
          vm.type = vm.$route.params.type;
        }
        vm.clearRegion = true;
      }
    });
  },
  methods: {
    getStoreList() {
      // this.listLoading = true;
      getStore({ look_del: 0, category_id: 564 }).then(res => {
        this.store_list = res;
      });
    },
    //获取供应商名称
    getSupplier() {
      supplier({}).then(res => {
        this.sup_list = res.data;
      });
    },
    //获取供应商信息
    getSupplierInfo(id) {
      let data = this.sup_list.filter(val => val.id == id);
      if (data.length > 0) {
        this.saveForm.receive_name = data[0].name;
      }
      supplierInfo({ id }).then(res => {
        this.saveForm.man_name = res.data.linkman ? res.data.linkman.name : '';
        this.saveForm.phone = res.data.linkman ? res.data.linkman.phone : '';
        this.saveForm.receive_name = res.data.name;
        this.saveForm.address = res.data.address;
        this.saveForm.prov = res.data.prov_id;
        this.saveForm.prov_name = res.data.prov_name;
        this.saveForm.city = res.data.city_id;
        this.saveForm.city_name = res.data.city_name;
        this.saveForm.dist = res.data.dist_id;
        this.saveForm.dist_name = res.data.dist_name;
        //     this.reg={
        //         prov: res.data.prov_id,
        //         city: res.data.city_id,
        //         area: res.data.dist_id
        //     }
      });
    },
    //获取中央仓名称
    getHouse() {
      house({}).then(res => {
        res.forEach(val => {
          val.id = val.house_id;
          val.name = val.house_name;
        });
        this.house_list = res;
      });
    },
    //获取中央仓信息
    getHouseInfo(id) {
      houseInfo({ house_id: id }).then(res => {
        this.saveForm.man_name = res.linkman;
        this.saveForm.receive_name = res.house_name;
        this.saveForm.phone = res.phone;
        this.saveForm.address = res.address;
        this.saveForm.prov = res.prov_id;
        this.saveForm.prov_name = res.prov_name ? res.prov_name : '';
        this.saveForm.city = res.city_id;
        this.saveForm.city_name = res.city_name ? res.city_name : '';
        this.saveForm.dist = res.dist_id;
        this.saveForm.dist_name = res.dist_name ? res.dist_name : '';
        this.reg = {
          prov: res.prov_id,
          city: res.city_id,
          area: res.dist_id
        };
      });
    },
    storeChange() {
      this.list = [];
    },
    typeChange(val) {
      this.saveForm.receice_id = '';
      this.saveForm.man_name = '';
      this.saveForm.phone = '';
      this.saveForm.address = '';
      this.saveForm.appoint_money = '';
      this.reg = {};
      this.rece_list = val == 1 ? this.sup_list : this.house_list;
    },
    receChange(id) {
      if (this.saveForm.type == 1) {
        this.getSupplierInfo(id);
      } else {
        this.getHouseInfo(id);
      }
    },
    inputBurl(row) {
      if (!positiveInt(row.order_num)) {
        row.order_num = 1;
      } else if (row.order_num > row.remain_num * 1 + (row.before_num ? row.before_num * 1 : 0)) {
        row.order_num = row.remain_num * 1 + (row.before_num ? row.before_num * 1 : 0);
      }
    },
    save() {
      let isPass = true;
      this.list.forEach(val => {
        if (!positiveInt(val.order_num)) {
          this.$message.error('退货数量只能为正整数');
          isPass = false;
          return;
        } else if (val.order_num * 1 > val.remain_num * 1 + (val.before_num ? val.before_num * 1 : 0)) {
          this.$message.error('退货数量不能大于可退数量');
          isPass = false;
          return;
        }
      });
      if (!isPass) {
        return;
      }
      this.showConDig = true;
      if (this.showType == 2 && this.isFirst) {
        this.rece_list = this.saveForm.type == 1 ? this.sup_list : this.house_list;
        setTimeout(() => {
          this.reg = {
            prov: this.saveForm.prov,
            city: this.saveForm.city,
            area: this.saveForm.dist
          };
        }, 0);
        this.isFirst = false;
      }
    },
    //修改、保存
    saveClick() {
      if (!this.saveForm.type) {
        this.$message.error('请选择退货渠道');
        return;
      }
      if (!this.saveForm.receice_id) {
        this.$message.error('请选择收货方');
        return;
      }
      if (this.saveForm.type == 1 && !this.saveForm.appoint_money) {
        this.$message.error('请输入约定退款金额');
        return;
      }
      if (this.saveForm.type == 1 && !greater0to999999dot(this.saveForm.appoint_money)) {
        this.$message.error('约定退款金额在0.01-999999.99之间');
        return;
      }
      if (this.saveForm.type == 2 && !this.saveForm.man_name) {
        this.$message.error('请输入联系人');
        return;
      }
      if (this.saveForm.type == 2 && !mobile(this.saveForm.phone)) {
        this.$message.error('请输入合法的手机号');
        return;
      }
      if (this.saveForm.type == 2 && !this.saveForm.city) {
        this.$message.error('请选择地区');
        return;
      }
      if (this.saveForm.type == 2 && !this.saveForm.address) {
        this.$message.error('请输入详细地址');
        return;
      }
      this.submit();
    },
    submit() {
      let saveForm = JSON.parse(JSON.stringify(this.saveForm));
      saveForm.all_num = this.allNum;
      saveForm.all_money = this.allTotal;
      saveForm.species_num = this.list.length;
      if (this.showType == 1) {
        let list = [];
        this.list.forEach(val => {
          let obj = {
            gift_id: val.gift_id,
            order_num: val.order_num,
            money_sell: val.money_cost,
            remark: ''
          };
          list.push(obj);
        });
        saveForm.gift_info = list;
      } else {
        saveForm.id = this.id;
        let data = [];
        let newData = this.list.filter(val => val.type == 1);
        newData.forEach(val => {
          data.push({ gift_id: val.gift_id, order_num: val.order_num, money_sell: val.money_cost, before_num: val.order_num, remark: '', type: 1 });
        });
        this.delData.forEach(val => {
          data.push({
            gift_id: val.gift_id,
            order_num: val.order_num,
            before_num: val.order_num,
            money_sell: val.money_cost,
            remark: '',
            type: 2,
            mapping_id: val.mapping_id
          });
        });
        let lastData = this.list.filter(val => val.type == 0);
        lastData.forEach(val => {
          let gift = this.oldData.find(item => item.gift_id == val.gift_id);
          if (gift.order_num != val.order_num) {
            data.push({
              gift_id: val.gift_id,
              order_num: val.order_num,
              money_sell: val.money_cost,
              type: 3,
              remark: '',
              mapping_id: val.mapping_id,
              before_num: gift.before_num
            });
          }
        });
        saveForm.gift_info = data;
      }
      setOrder(saveForm, this.showType).then(res => {
        if (res.code == 1) {
          this.showConDig = false;
          this.$message.success(res.message);
          this.$store.dispatch('delVisitedViews', this.route).then(() => {
            this.$router.push({ name: 'warehouse/returnOList', params: { routerflag: 1 } });
          });
        }
      });
    },
    //关闭
    closeOrder() {
      this.$confirm('确定关闭？将不可再次开启！', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        close({ id: this.id, status_type: 3, house_id: '', store_id: this.saveForm.store_id, type: this.saveForm.type, remark: '' }).then(res => {
          if (res.code == 1) {
            this.$message.success(res.message);
            this.$store.dispatch('delVisitedViews', this.route).then(() => {
              this.$router.push({ name: 'warehouse/returnOList', params: { routerflag: 1 } });
            });
          }
        });
      });
    },
    //移除
    delClick(index) {
      this.$confirm('确定移除？移除后数据不可恢复！', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let delGift = this.list.splice(index, 1)[0];
        if (delGift.type == 0) {
          this.delData.push(delGift);
        }
      });
    },
    //添加
    addClick(type) {
      if (type) {
        if (this.add_gift_info.remain_num * 1 < this.gift_num * 1) {
          this.$message.error('可退库存不足');
          return;
        }
        let index = this.list.findIndex(val => val.gift_id == this.add_gift_info.id);
        if (index >= 0) {
          this.list[index].order_num = this.list[index].order_num * 1 + this.gift_num * 1;
          this.list[index].remain_num = this.add_gift_info.remain_num;
        } else {
          this.list.unshift({
            type,
            gift_id: this.add_gift_info.id,
            money_cost: this.add_gift_info.money_cost,
            order_num: this.gift_num,
            img: this.add_gift_info.img,
            thumb: this.add_gift_info.thumb,
            isSave: true,
            box_num: this.add_gift_info.box_num,
            gift_name: this.add_gift_info.gift_name,
            remain_num: this.add_gift_info.remain_num
          });
        }
        this.addDialog = false;
      } else {
        if (!this.saveForm.store_id) {
          this.$message.error('请选择退货方！');
          return;
        }
        this.addDialog = true;
      }
    },
    // 子组件传过来的省
    provVal(val) {
      this.saveForm.prov = val[0];
      this.saveForm.prov_name = val[1];
    },
    // 子组件传过来的市
    cityVal(val) {
      this.saveForm.city = val[0];
      this.saveForm.city_name = val[1];
    },
    // 子组件传过来的区
    areaVal(val) {
      this.saveForm.dist = val[0];
      this.saveForm.dist_name = val[1];
    },
    //新增礼品弹窗重置
    addCallOf() {
      this.add_gift_info = {};
      this.gift_num = 1;
      this.addData.id = '';
    },
    //进入页面重置
    pageCallOf() {
      this.delData=[];
      this.list = [];
      this.rece_info = {};
      this.reg = {};
      this.saveForm.store_id = '';
      this.saveForm.type = '';
      this.saveForm.receice_id = '';
      this.saveForm.man_name = '';
      this.saveForm.phone = '';
      this.saveForm.address = '';
      this.saveForm.remark = '';
      this.saveForm.appoint_money = '';
    },
    confirmCallOf() {
      this.clearRegion = false;
    },
    //获取礼品信息
    showInfo(id) {
      this.gift_info = {};
      getGift({ id, type: 1, house_id: '', store_id: this.saveForm.store_id }).then(res => {
        if (res.code == 1) {
          res.data.money_cost = (res.data.money_cost / 1).toFixed(2);
          res.data.texture = res.data.texture == 'null' ? '' : res.data.texture;
          this.gift_info = res.data;
          this.infoDialog = true;
        }
      });
    },
    //搜索礼品
    searchClick() {
      this.add_gift_info = {};
      this.gift_num = 1;
      if (!this.addData.id) {
        this.$message.error('请输入礼品编号');
        return;
      }
      getGift({ id: this.addData.id, type: 1, house_id: '', store_id: this.saveForm.store_id }).then(res => {
        if (res.code == 1) {
          let data = res.data;
          data.money_cost = (data.money_cost / 1).toFixed(2);
          data.texture = data.texture == 'null' ? '' : data.texture;
          this.add_gift_info = data;
          this.gift_num = data.remain_num * 1 < data.box_num * 1 ? data.remain_num : data.box_num * 1 > 0 ? data.box_num : 1;
        }
      });
    },
    getData(data) {
      let allNum = 0,
        allTotal = 0;
      data.forEach(val => {
        val.isSave = this.showType == 2 ? true : false;
        val.type = 0;
        val.before_num = val.order_num;
        val.money_cost = (val.money_cost * 1).toFixed(2);
        val.all_money = (val.all_money / 1).toFixed(2);
        allNum += val.order_num * 1;
        allTotal += val.all_money * 1;
        if (this.type == 1) {
          val.arrive_num = this.status == 20 ? val.order_num : 0;
        }
        val.arrive_money = (val.arrive_num * val.money_cost).toFixed(2);
      });
      this.listNum = allNum;
      this.listTotal = allTotal;
      this.list = data;
      this.oldData = JSON.parse(JSON.stringify(data));
      // let page=val?val:1;
      // let obj={
      //     id:page,
      //     list:data
      // }
      // this.allList.push(obj);
      // this.oldData.push(JSON.parse(JSON.stringify(obj)))
    },
    //获取详情
    getOrderInfo() {
      getInfo({ id: this.id }).then(res => {
        this.order_no = res.data.order_id;
        this.typeSetNum = res.data.species_num * 1;
        this.allListNum = res.data.all_num * 1;
        this.allListTotal = res.data.all_money * 1;
        this.time = res.data.link_info.create_time;
        this.nick = res.data.link_info.clerk_s;
        this.remark = res.data.link_info.remark;
        this.saveForm.remark = res.data.remark;
        this.saveForm.type = res.data.type;
        this.saveForm.man_name = res.data.man_name;
        this.saveForm.phone = res.data.phone;
        this.saveForm.prov = res.data.prov;
        this.saveForm.city = res.data.city;
        this.saveForm.dist = res.data.dist;
        this.saveForm.prov_name = res.data.prov_name;
        this.saveForm.city_name = res.data.city_name;
        this.saveForm.dist_name = res.data.dist_name;
        this.saveForm.address = res.data.address;
        this.receice_id = res.data.receice_id;
        this.saveForm.receice_id = this.receice_id;
        this.saveForm.appoint_money = res.data.appoint_money ? (res.data.appoint_money * 1).toFixed(2) : '';
      });
    },
    fatchData() {
      this.listLoading = true;
      this.oldData = '';
      this.list = [];
      getList({ id: this.id, store_id: this.saveForm.store_id, house_id: '' })
        .then(res => {
          if (res.data.length > 0) {
            this.getData(res.data);
          }
          this.listLoading = false;
        })
        .catch(res => {
          this.listLoading = false;
        });
      // getPage({id:this.id,store_id:this.saveForm.store_id}).then(response=>{
      //     this.totalDataNumber = response.data.page * 20;
      // }).catch(res=>{
      //     this.listLoading=false;
      // })
    }
    // handleCurrentChange(val) {
    //     this.listLoading = true;
    //     this.list = [];
    //     getList({id:this.id,store_id:this.saveForm.store_id}, val).then(res => {
    //         this.getData(res.data)
    //         this.listLoading = false;
    //     });
    // }
  },
  computed: {
    allNum: function() {
      if (this.list.length <= 0) {
        return 0;
      }
      let num = 0;
      this.list.forEach(val => {
        num = num + val.order_num * 1;
      });
      return num;
    },
    allTotal: function() {
      if (this.list.length <= 0) {
        return 0;
      }
      let total = 0;
      this.list.forEach(val => {
        total = total + val.order_num * val.money_cost;
      });
      return total;
    }
    // allSetNum:function(){
    //     if(this.list.length==0){
    //         return 0;
    //     }
    //     let num=0;
    //     this.list.forEach(val=>{
    //         num=num+val.order_num*1;
    //     })
    //     return this.allListNum+num-this.listNum;
    // },
    // allSetTotal:function(){
    //     if(this.list.length<=0){
    //         return 0;
    //     }
    //     let total=0;
    //     this.list.forEach(val=>{
    //         total=total+val.order_num*val.money_cost;
    //     })
    //     return this.allListTotal+total-this.listTotal;
    // },
  },
  watch: {
    isSave: function(val) {
      this.list.forEach(item => {
        item.isSave = val;
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.detail_title {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.info_dialog {
  div + div {
    margin-top: 10px;
  }
}
.confirm_dialog {
  border: 1px solid #eee;
  border-radius: 5px;
  .text {
    padding: 10px;
    background: #efefef;
  }
  .checked {
    padding: 10px;
  }
}
.confirm_btn {
  padding-top: 20px;
  display: flex;
  justify-content: space-around;
}
.dialog-footer {
  text-align: right;
}
.gift_num {
  display: flex;
  margin-top: 10px;
  align-items: center;
  .num_tag {
    margin-right: 80px;
  }
}
.gift_img {
  height: 90px;
  text-align: center;
  padding: 10px;
}
.bottom_box {
  .total {
    margin: 8px;
    span {
      margin-right: 20px;
    }
  }
}
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
<style scoped>
.app-container >>> .el-dialog textarea {
  border-radius: unset;
  padding: 10px 15px;
}
.row-block {
  width: 100%;
  height: 50%;
  margin: 8px 0;
  display: flex;
  align-items: center;
}

.row-block-full {
  width: 100%;
  height: 100%;
  margin-top: 8px;
  display: flex;
  align-items: center;
}
</style>